package com.itcast.springboot.controller;

import com.itcast.springboot.bean.Admin;
import com.itcast.springboot.bean.CommonResult;
import com.itcast.springboot.bean.Feedback;
import com.itcast.springboot.service.AdminService;
import com.itcast.springboot.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "意见反馈相关的请求")
@RestController
@CrossOrigin
public class FeedbackController {

    @Resource
    FeedbackService feedbackService;

    //增（isRead和isSolve默认为0）
    @ApiOperation("增加意见反馈信息（包含上传截图）")
    @PostMapping("/feedbackUpload")
    public Integer insertFeedbackUpload(Feedback feedback, @RequestParam(value = "feedbackSrc", required = false) MultipartFile feedbackSrc,
                                  @RequestParam(value = "feedbackSrc2", required = false) MultipartFile feedbackSrc2) {
        return feedbackService.insertFeedbackUpload(feedback, feedbackSrc, feedbackSrc2);
    }
    //增加意见反馈信息（isRead和isSolve默认为0）
    @ApiOperation("增加意见反馈信息")
    @PostMapping("/feedback")
    public Integer insertFeedback(@RequestBody Feedback feedback) {
        return feedbackService.insertFeedback(feedback);
    }
    @ApiOperation("增加反馈截图1")
    @PostMapping("/feedbackSrc")
    public String insertFeedbackSrc(MultipartFile feedbackSrc) {
        return feedbackService.insertFeedbackSrc(feedbackSrc);
    }
    @ApiOperation("增加反馈截图2")
    @PostMapping("/feedbackSrc2")
    public String insertFeedbackSrc2(MultipartFile feedbackSrc2) {
        return feedbackService.insertFeedbackSrc2(feedbackSrc2);
    }

    //通过isRead和isSolve自定义规则删除信息：全部信息、未读未解决、已读为解决、已读已解决
    @ApiOperation("通过isRead和isSolve自定义规则删除信息：全部信息、未读未解决、已读为解决、已读已解决")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isRead", value = "是否已读"),
            @ApiImplicitParam(name = "isSolve", value = "是否解决")
    })
    @DeleteMapping(value = {"/feedbacksTrim/{isRead}/{isSolve}"})
    public Integer deleteFeedbackTrim(@PathVariable(value = "isRead", required = false) Integer isRead,
                                      @PathVariable(value = "isSolve", required = false) Integer isSolve) {
        return feedbackService.deleteFeedbackTrim(isRead, isSolve);
    }
    //根据id删除
    @ApiOperation("根据id删除")
    @DeleteMapping(value = {"/feedback/{fbid}"})
    public Integer deleteFeedbackById(@PathVariable("fbid") Integer fbid){
        return feedbackService.deleteFeedbackById(fbid);
    }


    //通过isRead和isSolve自定义规则查询信息：全部信息、未读未解决、已读为解决、已读已解决
    @ApiOperation("通过isRead和isSolve自定义规则查询信息：全部信息、未读未解决、已读为解决、已读已解决")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isRead", value = "是否已读"),
            @ApiImplicitParam(name = "isSolve", value = "是否解决")
    })
    @GetMapping(value = {"/feedbacksTrim/{isRead}/{isSolve}"})
    public List<Feedback> getFeedbackSolvesTrim(@PathVariable(value = "isRead", required = false) Integer isRead,
                                                @PathVariable(value = "isSolve", required = false) Integer isSolve) {
        return feedbackService.getFeedbackSolvesTrim(isRead, isSolve);
    }

    //修改isRead和isSolve状态：未读改为已读、已读改为已解决
    @ApiOperation("修改isRead和isSolve状态：未读改为已读、已读改为已解决")
    @PutMapping("/feedback")
    public Integer updateFeedback(@RequestBody Feedback feedback) {
        return feedbackService.updateFeedback(feedback);
    }

}
